﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Web.UI.WebControls;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;

/// <summary>
/// 将数据导出成Excel文件的类
/// 数据列的顺序按照 Gridview中列的顺序
/// </summary>
namespace HZ.DrugTrade.Web
{
    public class Function
    {
        /// <summary>
        /// 格式化产品属性
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string FormatDrugSource(object obj)
        {
            string status = "未知";

            try
            {
                if (obj != null)
                {
                    switch (Convert.ToInt16(obj))
                    {
                        case 0: status = "<font color=black>限价竞价</font>";
                            break;
                        case 1: status = "<font color=red>重点监控</font>";
                            break;
                        case 3: status = "<font color=blue>备案采购</font>";
                            break;
                    }
                }
            }
            catch (Exception)
            {

            }

            return status;
        }

        /// <summary>
        /// 根据项目格式化价格属性
        /// </summary>
        /// <param name="Projectid"></param>
        /// <param name="Price"></param>
        /// <returns></returns>
        public static string FormPrice(object Projectid, object Price)
        {
            if (Projectid == null)
            {
                return Price == null ? "0.0000" : Convert.ToDecimal(Price).ToString("F4");
            }
            else
            {
                if (Projectid.ToString() == "0002")//高值耗材精确到后两位
                {
                    return Convert.ToDecimal(Price == null ? 0 : (Price.ToString() == "" ? 0 : Price)).ToString("F2");
                }
                else
                {
                    return Convert.ToDecimal(Price == null ? 0 : (Price.ToString() == "" ? 0 : Price)).ToString("F4");
                }
            }
        }

        /// <summary>
        /// 判断是否为可以采购高值耗材
        /// </summary>
        /// <returns></returns>
        public static bool IsThreeLevel()
        {
            IBLL_Hospital ih = Factory.BLL_Hospital();
            string hID = CurrentAccount.Account.Org.OrgID;
            Model.HospitalInfo hospital = ih.GetHospitalInfoByID(hID);
            if (hospital != null)
            {
                if (hospital.IsHcygcg == 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }



        /// <summary>
        /// 格式化产品类别
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string FormatDrugBasicRemedy(object obj)
        {
            string status = "未知";
            try
            {
                if (obj != null)
                {
                    switch (Convert.ToInt16(obj))
                    {
                        case 0: status = "<font color=red>基本药物</font>";
                            break;
                        case 1: status = "<font color=black>非基本药物</font>";
                            break;
                    }
                }
            }
            catch (Exception)
            {

            }
            return status;
        }

        /// <summary>
        /// 格式化产品类别
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string FormatDrugBasicRemedy1(object obj)
        {
            string status = "未知";
            try
            {
                if (obj != null)
                {
                    switch (Convert.ToInt16(obj))
                    {
                        case 0: status = "<font color=red>内蒙基药</font>";
                            break;
                        case 1: status = "<font color=black> </font>";
                            break;
                    }
                }
            }
            catch (Exception)
            {

            }
            return status;
        }

        /// <summary>
        /// 获取产品页面链接
        /// </summary>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        public static string GetGoodsUrl(object goodsid)
        {
            string goodsUrl = "";
            try
            {
                if (goodsid != null)
                {
                    if (goodsid.ToString().Length == 13) //低值
                    {
                        goodsUrl = "<a href=\"../../GoodsInfo.aspx?goodsid=" + goodsid.ToString() + "\" target=\"_blank\">" + goodsid.ToString() + "</a>";
                    }
                    else
                    {
                        goodsUrl = "<a href=\"../../CommonPage/GoodsInfo_GZHC.aspx?id=" + goodsid.ToString() + "\" target=\"_blank\">" + goodsid.ToString() + "</a>";
                    }
                }
            }
            catch (Exception)
            {

            }
            return goodsUrl;
        }


        /// <summary>
        /// 获取地区数据
        /// 提供个js地区下拉选择库使用
        /// </summary>
        /// <returns></returns>
        protected string GetCityData()
        {
            string city_data = "";
            IBLL_Area areaCtrl = Factory.BLL_Area();
            IList<HZ.DrugTrade.Model.Area> areaList = areaCtrl.GetAllArea();
            foreach (HZ.DrugTrade.Model.Area area in areaList)
            {
                city_data += area.AreaID + "|" + area.AreaName + ",";
            }
            city_data = city_data.TrimEnd(',');

            return city_data;
        }

        

    }

}
